package com.itheima.app.controller;

import com.itheima.app.manager.MovementManager;
import com.itheima.app.manager.SettingsManager;
import com.itheima.app.manager.UserManager;
import com.itheima.domain.db.Notification;
import com.itheima.domain.mongo.Movement;
import com.itheima.domain.vo.MovementVo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.domain.vo.SettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class MovementController {

    @Autowired
    private MovementManager movementManager;
    /**
     * 发布我的动态
     * 参数1: 传输的文本
     * 参数2: 传输的图片
     */
    @PostMapping("/movements")
    public Map movements(Movement movement, MultipartFile[] imageContent) throws IOException {
        movementManager.addMovement(movement , imageContent );
        return  null;
    }


    /**
     * 根据用户的id查询用户的动态
     * ---- 查询我的动态
     */
    @GetMapping("/movements/all")
    public PageBeanVo findMovementByUserId(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize ,
            Long userId
    ) throws IOException {

        return  movementManager.findMovementByUserId(page , pageSize ,userId);
    }



    /**
     * 查询好友动态
     */
    @GetMapping("/movements")
    public PageBeanVo findFriendMovement(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {

        return  movementManager.findFriendMovement(page , pageSize );
    }


    /**
     * 查询推荐动态
     */
    @GetMapping("/movements/recommend")
    public PageBeanVo findRecommendMovement(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {

        return  movementManager.findRecommendMovement(page , pageSize );
    }

    /**
     * 点赞
     */
    @GetMapping("/movements/{publishId}/like")
    public Integer commentLike(
            @PathVariable String publishId
    ) throws IOException {

        return  movementManager.commentLike(publishId );
    }
    /**
     * 取消点赞
     */
    @GetMapping("/movements/{publishId}/dislike")
    public Integer commentDisLike(
            @PathVariable String publishId
    ) throws IOException {

        return  movementManager.commentDisLike(publishId );
    }

    //动态喜欢
    @GetMapping("/movements/{id}/love")
    public Integer saveMovementLove(@PathVariable("id") String MovementId) {
        return movementManager.saveMovementLove(MovementId);
    }


    //动态取消喜欢
    @GetMapping("/movements/{id}/unlove")
    public Integer deleteMovementLove(@PathVariable("id") String MovementId) {
        return movementManager.deleteMovementLove(MovementId);
    }


    /**
     * 单条动态
     */
    @GetMapping("/movements/{movementId}")
    public MovementVo findMovementVo(
            @PathVariable String movementId
    ) throws IOException {

        return  movementManager.findMovementVo(movementId );
    }




    /**
     * 评论列表
     */
    @GetMapping("/comments")
    public PageBeanVo findFriendMovement(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize,
            String movementId
    ) throws IOException {

        return  movementManager.findCommentList(page , pageSize , movementId );
    }

    /**
     * 发表评论
     */
    @PostMapping("/comments")
    public Integer saveComment(@RequestBody Map map) throws IOException {
        String movementId = map.get("movementId").toString(); //动态id
        String comment = map.get("comment").toString(); //评论的内容

        return  movementManager.saveComment(movementId , comment );
    }




    /**
     * 点赞列表
     */
    @GetMapping("/messages/likes")
    public PageBeanVo messagesLikes(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {

        int commentType = 1;//点赞
        return  movementManager.messagesByCommentType(page , pageSize  , commentType);
    }

    /**
     * 评论列表
     */
    @GetMapping("/messages/comments")
    public PageBeanVo messagesComments(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {
        int commentType = 2;//评论
        return  movementManager.messagesByCommentType(page , pageSize , commentType  );
    }

    /**
     * 喜欢列表
     */
    @GetMapping("/messages/loves")
    public PageBeanVo messagesLoves(
            @RequestParam(defaultValue = "1") Integer page ,
            @RequestParam(defaultValue = "10") Integer pageSize
    ) throws IOException {
        int commentType = 3;//喜欢
        return  movementManager.messagesByCommentType(page , pageSize , commentType  );
    }


    /*
     *
     *  公告列表
     * @param page
     * @param pageSize
     * @author
     * @date
     * @return com.itheima.domain.vo.PageBeanVo
     */

    @GetMapping("/messages/announcements")
    public PageBeanVo messagesAnnouncements(@RequestParam(defaultValue = "2") Integer page ,
                                            @RequestParam(defaultValue = "3") Integer pageSize
    ) throws IOException {
        return  movementManager.messagesAnnouncements(page ,pageSize);
    }

    //动态评论点赞
    @GetMapping("/comments/{commentId}/like")
    public Integer movementCommentLike(@PathVariable String commentId){
        //调用manager
        return movementManager.movementCommentLike(commentId);
    }

    //动态评论取消点赞
    @GetMapping("/comments/{commentId}/dislike")
    public Integer movementCommentNotLike(@PathVariable String commentId){
        //调用manager
        return movementManager.movementCommentdisLike(commentId);
    }


}
